package com.lvy.hczn.transmit.controller;

import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.mq.rocket.ParamInfo;
import com.lvy.hczn.transmit.domain.dto.cteck.PackSpecDto;
import com.lvy.hczn.transmit.service.TPackSpecService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/api/dt/pack/spec/")
@RestController
@Slf4j
public class TPackSpecController {

    @Autowired
    private TPackSpecService tPackSpecService;

    /**
     * 平台推送包装袋规格信息
     *
     * @param request
     * @param info
     */
    @ApiOperation(value = "平台推送包装袋规格信息", notes = "平台推送包装袋规格信息")
    @PostMapping("data")
    public AjaxResult syncPackSpecFromPlatForm(HttpServletRequest request, @RequestBody ParamInfo info) {
        try {
            tPackSpecService.syncPackSpecFromPlatForm(request, info);
            return AjaxResult.success();
        } catch (Exception e) {
            if (e instanceof UtilException) {
                return AjaxResult.error(e.getMessage());
            } else {
                log.error("syncPackSpecFromPlatForm同步异常：{}", e);
                return AjaxResult.error("系统异常");
            }
        }
    }
}
